<template>
  <c-table
    ref="cTable"
    selection
    hasBorder
    :size="size"
    :max-height="maxHeight"
    :loading="isLoading"
    :table-header="tableHeader"
    :table-list="tableList"
    :page-info="pageInfo"
    :table-inner-btns="tableInnerBtns"
    @change-pagination="changePagination"
  >
    <template v-slot:header>
      <c-search
        :form-model="searchObj"
        :form-items="searchItems"
        @submit-form="searchSubmit"
        @reset-form="searchReset"
      ></c-search>
    </template>
  </c-table>
</template>
<script>
import mixinTable from 'mixins/table'
import dictObj from '@/store/dictData'

export default {
  name: '{{camelCase firstName}}List',
  mixins: [mixinTable],
  props: {
    // TODO...
  },
  data(vm) {
    return {
      tableInnerBtns: [
        {
          width: 130,
          name: '编辑',
          icon: 'el-icon-edit',
          handle(row) {
            const { id } = row
            vm.$emit('showDialog', {
              title: '编辑标签',
              initData: {
                id
                // TODO...
              },
              isEdit: true
            })
          }
        },
        {
          name: '删除',
          icon: 'el-icon-delete',
          handle(row) {
            const { tagName, id } = row
            vm.confirmTip(`确认删除${tagName}标签`, () => {
              vm.deleteData({ id })
            })
          }
        }
      ],
      tableHeader: [
        // {
        //   label: '标签名称',
        //   prop: 'tagName',
        //   fixed: true,
        //   search: {
        //     type: 'input'
        //   }
        // },
        // {
        //   label: '标签值',
        //   prop: 'tagValues',
        //   formatter(row) {
        //     return row.tagValues.map(item => item.value).filter(d => d).join('/')
        //   },
        //   search: {
        //     type: 'input',
        //     prop: 'value'
        //   }
        // },
        // {
        //   label: '标签状态',
        //   prop: 'tagStatus',
        //   formatter(row) {
        //     return row && vm.setTableColumnLabel(row.tagStatus, 'disStatus')
        //   },
        //   search: {
        //     type: 'dict',
        //     optionsList: dictObj.disStatus
        //   }
        // },
        {
          label: '创建时间',
          prop: 'created',
          search: {
            prop: 'dateTime',
            type: 'dateTime'
          }
        },
        {
          label: '更新时间',
          prop: 'updated'
        }
      ]
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      const { dateTime, ...other } = this.searchObj
      const { totalNum, ...page } = this.pageInfo
      const searchDate = this.getSearchDate(dateTime)
      this.isLoading = true
      this.$api.{{camelCase apiFile}}.query{{properCase firstName}}({
        ...searchDate,
        ...other,
        ...page
      }).then(res => {
        this.isLoading = false
        if (res && res.totalCount) {
          const { data, totalCount } = res
          this.pageInfo.totalNum = totalCount
          this.tableList = data || []
        } else {
          this.tableList = res || []
        }
      })
    },
    deleteData(param, msgTip = '删除成功') {
      this.$api.{{camelCase apiFile}}.delete{{properCase firstName}}(param).then(() => {
        this.$msgTip(msgTip)
        this.delResetData()
      })
    }
  }
}
</script>
